package com.learn.codesourcelearn.spring;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class AnimalInvocationHandler implements InvocationHandler {
    private Object target;

    public Object bind(Object target) {
        this.target = target;
        return Proxy.newProxyInstance(target.getClass().getClassLoader(),target.getClass().getInterfaces(),this);
    }
    @Override
    public Object invoke(Object proxy,Method method,Object[] args) throws Throwable{
        Object result = null;
        System.out.println("----调用前处理");
        result = method.invoke(target,args);
        System.out.println("----调用后处理");
        return result;
    }
}
